from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings
from apscheduler.schedulers.twisted import TwistedScheduler

from viewspotcomments.spiders.viewspotcomments import ViewSpotComments

try:
    # 读取setting配置文件
    process = CrawlerProcess(get_project_settings())
    sched = TwistedScheduler()
    # sched.add_job(process.crawl, 'interval', args=[ViewSpotComments], day='*', hour='06', minute='00')
    # 添加作业，每天3点执行一次
    sched.add_job(process.crawl, 'cron', args=[ViewSpotComments], day='*', hour='03', minute='00')
    # sched.add_job(process.crawl, 'interval', args=[Today_Weather], seconds=20)
    sched.start()
    """
    sched1 = TwistedScheduler()
    sched1.add_job(process.crawl, 'interval', args=[Today_Weather], seconds=30)
    sched1.start()
    """
    process.start(False)
except(KeyboardInterrupt, SystemExit):
    sched.shutdown()
    print('Exit The Job!')
